import React, {PropsWithChildren} from 'react'
import MarketEditForm from "../components/MarketEditForm";
import {createMarket, MarketDetailResponse} from "../apis/MarketsApi";
import {observer} from "mobx-react";
import marketPageStackStore from "../store/MarketPageStackStore";
import Taro from "@tarojs/taro";
import MyNavigationBar from "../components/MyNavigationBar";

export interface MarketAddProps extends PropsWithChildren {

}

const MarketAdd: React.FC<MarketAddProps> = ({}) => {
    return <>
        <MyNavigationBar>添加商品</MyNavigationBar>
        <MarketEditForm onConfirm={async (value, data) => {
            createMarket(value).then(response => {
                const detail: MarketDetailResponse = {
                    ...data,
                    id: response.data,
                    goodsAmount: 0,
                    orderAmount: 0,
                }
                marketPageStackStore.appendItemByDetail(detail)
                Taro.navigateBack()
            })
        }}/>
    </>
}

export default observer(MarketAdd)


